package strcy.cn.market.exception;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import strcy.cn.market.utils.Result;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 捕捉 ConstraintViolationException 异常，并且返回提示信息
     * @param e 错误信息
     * @return 返回提示信息
     */
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandle(Exception e) {
        e.printStackTrace();
        return  Result.error(StringUtils.hasLength(e.getMessage())? e.getMessage() : "操作失败");
    }
}
